#!/usr/bin/perl

use strict;
 
use DBI;
use CGI;
use TTraker;


print_header ();
my $dbh;
initialize_dbi();

my $query = CGI->new;
my $num = $query->param('num');
my $name = $query->param('name');
my $job = $query->param('job');
my $loc = $query->param('loc');
my $dir = $query->param('dir');

select_client ($num, $name, $job, $loc, $dir);

############### SUBROUTINES FOLLOW ###############

sub select_client
{
my $num = $_[0];
my $name = $_[1];
my $job = $_[2];
my $loc = $_[3];
my $dir = $_[4];

my $client_ref = get_clients_not_on_hot_list($num);
my @clients = @$client_ref;

print <<ENDHEADER;
<html>
<head>
<link rel='stylesheet' type='text/css' href='${css_ref}trak.css' />
<script type='text/javascript' src='${js_ref}trak.js'></script>
<title>trak_02_adm_activity.html</title>
</head>
<body onload='startTime_csr()'>
<div id='clock_csr'></div><br/>
<hr/>

<form id='box6_0' autocomplete='off' name='startJob' action='${cgi_ref}trak_03_csr_add_hot_list_client.pl' method='post'>
<h3>Add Client</h3>
<input type="hidden" name=empNum value='$num'/>
<input type="hidden" name=empName value='$name'/>
<input type="hidden" name=empJob value='$job'/>
<input type="hidden" name=empLoc value='$loc'/>
<input type="hidden" name=empDir value='$dir'/>
<select id=cliID name="cliID" tabindex=1 >
ENDHEADER
# add a MASTER element at the start of the list
# print "<option value='NUL'></option>";
# add all clients on the list to the drop down
foreach my $cli (@clients) {
   print "<option value=$cli >$cli</option>";
}
print <<ENDHEADER;
</select>
<br/><br/>
<input type='submit' name='submit' value='Add Client'>
<br/><br/>
<a href="${cgi_ref}trak_00_csr_activity.pl?num=$num&name=$name&job=$job&loc=$loc">Return</a>
<br/><br/>
</form>
</body>
</html>

ENDHEADER

}

sub select_client_std_time
{
my $num = $_[0];
my $name = $_[1];
my $job = $_[2];
my $loc = $_[3];
my $client_ref = get_clients;
my @clients = @$client_ref;

print <<ENDHEADER;
<html>
<head>
<link rel='stylesheet' type='text/css' href='${css_ref}trak.css' />
<script type='text/javascript' src='${js_ref}trak.js'></script>
<title>trak_02_adm_activity.html</title>
</head>
<body onload='startUp1()'>
<h2><center>${banner}</center></h2>
<hr/>
<div id='clock'></div>
<div id='box1'>
Employee Number:<br/><br/>
Employee Name:<br/><br/>
Select Client:<br/><br/>
</div>
<form id='box2' autocomplete='off' name='startJob' action='${cgi_ref}trak_03_adm_adjust_std_time.pl' method='post'>
<input type="hidden" name=empNum value='$num'/>
<input type="hidden" name=empName value='$name'/>
<input type="hidden" name=empJob value='$job'/>
<input type="hidden" name=empLoc value='$loc'/>
<span>$num</span><br/><br/>
<span>$name</span></b><br/><br/>
<select id=cliID name="cliID" tabindex=1 >
ENDHEADER
# add a MASTER element at the start of the list
# print "<option value='NUL'></option>";
# add all clients on the list to the drop down
foreach my $cli (@clients) {
   print "<option value=$cli >$cli</option>";
}
print <<ENDHEADER;
</select>
<br/><br/>
<input type='submit' name='submit' value='Proceed'>
<br/><br/>
<a href="${cgi_ref}trak_00_sup_activity.pl?num=$num&name=$name&job=$job&loc=$loc">Return to Activities</a>
</form>
</body>
</html>

ENDHEADER

}


sub adjust_master_std_time
{
my $num = $_[0];
my $name = $_[1];
my $job = $_[2];
my $loc = $_[3];
  my $mas_task_ref = get_adm_master_task_list;
  my @master_tasks = @$mas_task_ref;
  my $cli;
#  print "2 adm_master_std_time WERE IN!<br/>";
  print <<ENDHEADER;
  <html>
  <head>
  <link rel='stylesheet' type='text/css' href='${css_ref}trak.css' />
  <script type='text/javascript' src='${js_ref}trak.js'></script>
  <title>trak_03_adm_adjust_std_time.pl</title>
  </head>
  <body>
  <h2><center>${banner}</center></h2>
  <hr/>
  <div id='box5_1'>
  <h3>Adjust Standard Time for Master Tasks</h3>
  <form onkeypress='return event.keyCode != 13;' autocomplete='off'  name='activity' action='${cgi_ref}trak_04_adm_adjust_master_std_time.pl' method='post'>
<input type="hidden" name=empNum value='$num'/>
<input type="hidden" name=empName value='$name'/>
<input type="hidden" name=empJob value='$job'/>
<input type="hidden" name=empLoc value='$loc'/>
  <table>
    <tr>
      <th>Code</th>
      <th>Description</th>
      <th>Units</th>
      <th>Std Time</th>
      <th>&nbsp&nbsp&nbsp</th>
      <th>New Std</th>
    </tr>
ENDHEADER
# print "THERE ARE $#master_tasks TASKS!<br/>"; 
 for my $i (0..$#master_tasks ) {
   my $cli = $master_tasks[$i][0];
   my $code = $master_tasks[$i][1];
   my $desc = $master_tasks[$i][2];
   my $units = $master_tasks[$i][3];
   my $curStd = $master_tasks[$i][4];
   print <<ENDHEADER;
   <tr>
     <td>&nbsp&nbsp&nbsp $code</td>
     <td>&nbsp&nbsp&nbsp $desc</td>
     <td>&nbsp&nbsp&nbsp $units</td>
     <td>&nbsp&nbsp&nbsp $curStd</td>
     <td>&nbsp&nbsp&nbsp</td>
     <td><input type='text' size='6' name='new_std_${code}'/></td>
   </tr>
ENDHEADER
 }
 print <<ENDHEADER;
 </table>
 <br/><br/>
 <input type='submit' value='Adjust Master Standard Time'>
 <br/><br/>
 <a href="${cgi_ref}trak_00_adm_activity.pl?num=$num&name=$name&job=$job&loc=$loc">Return to Activities</a>
 <br/><br/>
 </form>
 </body>
 </html>
ENDHEADER
# print "DONE!<br/>";
}

sub add_new_client
{
my $num = $_[0];
my $name = $_[1];
my $job = $_[2];
my $loc = $_[3];
print <<ENDHEADER;
  <html>
  <head>
  <link rel='stylesheet' type='text/css' href='${css_ref}trak.css' />
  <script type='text/javascript' src='${js_ref}trak.js'></script>
  <title>trak_03_adm_add_new_client.pl</title>
  </head>
  <body>
  <h2><center>${banner}</center></h2>
  <hr/>
  &nbsp&nbsp&nbsp&nbsp&nbsp
  <div id = "box5_1"> 
  <h3>Add New Client</h3>
  </div>
<div id="box1">
  &nbsp&nbsp&nbsp&nbsp&nbsp Client ID: <br/><br/>
  &nbsp&nbsp&nbsp&nbsp&nbsp Location #: <br/><br/>
  &nbsp&nbsp&nbsp&nbsp&nbsp Client Name: <br/><br/>
</div>
<form id="box2" autocomplete="off" name="empID" action="${cgi_ref}trak_03_add_new_client.pl" method="post">
<input type="hidden" name=empNum value='$num'/>
<input type="hidden" name=empName value='$name'/>
<input type="hidden" name=empJob value='$job'/>
<input type="hidden" name=empLoc value='$loc'/>
  <input type="text" size=12 name=cliID />&nbsp&nbsp
  <br/><br/>
   <input type="text" size=6 name=locNum />&nbsp&nbsp
   <br/><br/>
   <input type="text" size=30 name=cliName />&nbsp&nbsp
   <br/><br/><br/>
   <input type="submit" value="Add New Client">
   <br/><br/><br/>
 <a href="${cgi_ref}trak_00_adm_activity.pl?num=$num&name=$name&job=$job&loc=$loc">Return to Activities</a>
 </form>
 </div>
 </body>
 </html>
ENDHEADER
}

sub select_client_add_task
{
my $num = $_[0];
my $name = $_[1];
my $job = $_[2];
my $loc = $_[3];
my $client_ref = get_clients;
my @clients = @$client_ref;

print <<ENDHEADER;
<html>
<head>
<link rel='stylesheet' type='text/css' href='${css_ref}trak.css' />
<script type='text/javascript' src='${js_ref}trak.js'></script>
<title>trak_02_adm_activity.html</title>
</head>

<body onload='startUp1()'>

<h2><center>${banner}</center></h2>
<hr/>
<div id='box5_1'>
<h3>Add New Task for a Client</h3>
Employee Number:<br/><br/>
Employee Name:<br/><br/>
Select Client:<br/><br/>
New Task ID:<br/><br/>
</div>
<form id='box2_3' autocomplete='off' name='startJob' action='${cgi_ref}trak_03_adm_add_client_task.pl' method='post'>
<input type="hidden" name=empNum value='$num'/>
<input type="hidden" name=empName value='$name'/>
<input type="hidden" name=empJob value='$job'/>
<input type="hidden" name=empLoc value='$loc'/>
<span>$num</span><br/><br/>
<span>$name</span></b><br/><br/>
<select id=cliID name="cliID" tabindex=1 >
ENDHEADER
# add a MASTER element at the start of the list
# print "<option value='NUL'></option>";
# add all clients on the list to the drop down
foreach my $cli (@clients) {
   print "<option value=$cli >$cli</option>";
}
print <<ENDHEADER;
</select>
<br/><br/>
<input type="text" size=10 name=taskID />&nbsp&nbsp
<br/><br/>
<input type='submit' name='submit' value='Proceed'>
<br/><br/>
<a href="${cgi_ref}trak_00_adm_activity.pl?num=$num&name=$name&job=$job&loc=$loc">Return to Activities</a>
<br/><br/>
</form>
</body>
</html>

ENDHEADER

}

sub add_new_master_task
{
my $num = $_[0];
my $name = $_[1];
my $job = $_[2];
my $loc = $_[3];
print <<ENDHEADER;
<html>
<head>
<link rel='stylesheet' type='text/css' href='${css_ref}trak.css' />
<script type='text/javascript' src='${js_ref}trak.js'></script>
<title>trak_02_adm_activity.html</title>
</head>
<h2><center>${banner}</center></h2>
<hr/>
<div id='box5_1'>
<h3>Add New Master Task</h3>
Employee Number:<br/><br/>
Employee Name:<br/><br/>
New Task ID:<br/><br/>
</div>
<form id='box2_3' autocomplete='off' name='startJob' action='${cgi_ref}trak_03_adm_add_master_task.pl' method='post'>
<input type="hidden" name=empNum value='$num'/>
<input type="hidden" name=empName value='$name'/>
<input type="hidden" name=empJob value='$job'/>
<input type="hidden" name=empLoc value='$loc'/>
<span>$num</span><br/><br/>
<span>$name</span><br/><br/>
<input type="text" size=10 name=taskID />&nbsp&nbsp
<br/><br/>
<input type='submit' name='submit' value='Proceed'>
<br/><br/>
<a href="${cgi_ref}trak_00_adm_activity.pl?num=$num&name=$name&job=$job&loc=$loc">Return to Activities</a>
<br/><br/>
</form>
</body>
</html>

ENDHEADER

}


